import { http } from '@/services/request'
import type { IUnknownObjProps } from '@/interface/base.interface'
import type { IUserBase } from '@/interface/types/idt/user.interface'
import type { IMenuItem } from '@/interface/types/pow/menu.interface'
import type { UsernameProps } from '@/stores/interface/auth'

interface IPerms {
  user: IUserBase
  menus: IMenuItem[]
  perms: IMenuItem[]
}

export const AccountService = {
  async doLoginApi(data: UsernameProps): Promise<{ access_token: string; refresh_token: string }> {
    return http.post('/api/core/auth/login/', {
      username: data.data?.username || '',
      password: data.data?.password || '',
    })
  },

  async doLogoutApi(): Promise<void> {
    return http.post('/api/v1/admin/account/logout')
  },

  async doRegisterApi(data: IUnknownObjProps): Promise<void> {
    return http.post('/api/core/auth/register', data)
  },

  async getPermsApi(): Promise<IPerms> {
    return http.get('/api/core/auth/perms')
  },
}
